﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using QxFramework.Core;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class TeachPPT : UIBase
{
    public Button NextButton;
    public Button LastButton;
    private int NowPage=0;
    public List<Sprite> PageNameList = new List<Sprite>();
    private void Awake()
    {
        NextButton.onClick.SetListener(() =>
        {
            NowPage++;
            UpdateSprite();
            if (NowPage == PageNameList.Count - 1)
            {
                this.transform.Find("Next").gameObject.SetActive(false);
            }
            else
            {
                this.transform.Find("Next").gameObject.SetActive(true);
                this.transform.Find("Last").gameObject.SetActive(true);
            }
        });
        LastButton.onClick.SetListener(() =>
        {
            NowPage--;
            UpdateSprite();
            if (NowPage == 0)
            {
                this.transform.Find("Last").gameObject.SetActive(false);
            }
            else
            {
                this.transform.Find("Last").gameObject.SetActive(true);
                this.transform.Find("Next").gameObject.SetActive(true);
            }
        });
        this.GetComponent<Image>().sprite = PageNameList[0];

        this.transform.Find("Close").GetComponent<Button>().onClick.SetListener(() => {

            ProcedureManager.Instance.ChangeTo<SceneLoadProcedure>(new SceneLoadPair(LevelManager.Instance.FirstLevel, typeof(GameProcedure)));
        
        
        });
    }
    public override void OnDisplay(object args)
    {
        base.OnDisplay(args);
        NowPage = 0;
        this.transform.Find("Last").gameObject.SetActive(false);
    }

    void UpdateSprite()
    {
        this.GetComponent<Image>().sprite= PageNameList[NowPage];
    }
}
